package org.dreamwork.modbus.tcp.protocol;

import org.dreamwork.modbus.protocol.ModbusADU;

public class TcpADU extends ModbusADU {
    /** modbus-tcp 头 */
    public MBAP header;

    @Override
    public byte[] toByteArray () {
        byte[] body = pdu.toByteArray ();
        header.length = body.length + 1;
        byte[] mbap = header.toByteArray ();
        byte[] buff = new byte[7 + body.length];    // mbap 定长，7个字节
        System.arraycopy (mbap, 0, buff, 0, 7);
        System.arraycopy (body, 0, buff, 7, body.length);
        return buff;
    }
}